package org.shangda.wechat.pet.web.vo;

import com.alibaba.fastjson.JSONObject;

import java.util.Map;

/**
 * @author Jason
 * @create 2020-07-07 11:17 上午
 **/
public class BaseRequest {
    private JSONObject sort;

    /**
     * 排序字段
     */
    private String sortName;

    /**
     * desc 降序 ，asc 升序
     */
    private String sortDir;

    /**
     * 页面记录数
     */
    private Integer pageSize = 10;

    /**
     * 当前页
     */
    private Integer pageNum = 1;

    public boolean pagable() {
        return getPageNum() != null && getPageSize() != null
                && getPageNum() > 0 && getPageSize() > 0;
    }

    public void disablePage() {
        setPageNum(0);
        setPageSize(0);
    }

    public Integer getPageNum() {
        return pageNum;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public JSONObject getSort() {
        return sort;
    }

    public String getSortDir() {
        return sortDir;
    }

    public String getSortName() {
        return sortName;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public void setSort(JSONObject sort) {
        this.sort = sort;
        if (sort != null) {
            for (Map.Entry<String, Object> entry : sort.entrySet()) {
                sortName = entry.getKey();
                sortDir = entry.getValue().toString();
            }
        }
    }

    public void setSortDir(String sortDir) {
        this.sortDir = sortDir;
    }

    public void setSortName(String sortName) {
        this.sortName = sortName;
    }
}
